//#slay
//Pticin G.A.
//2103/1


#include <graphics.h>
#include <stdio.h>


FILE *outf;      
   int I,J,N,M,L,O,m,i,k,ch;
   double F[20][20],S[20],X[20],X1[20],eps,mo;

main()
{ 
   initwindow(400,300);  
   outf = stdout;     

   fprintf(outf,"garfik zavisimosti symmi modylei reshenii ot epselon\n");              
   fprintf(outf, "Pticin G.A.\n");
   fprintf(outf, "gryppa 2103/1\n");
   fprintf(outf, "03.11.12\n");
   fprintf(outf, "\n"); 
    N=4;
    M=N;
    O=N;
//    eps=0.000000000000001;
    moveto(10,10);
    lineto(10,270);
    lineto(360,270);
    for(i=10;i<=260;i=i+10)
    {
       moveto(8,i);
       lineto(12,i);
    }
    for(i=10;i<=350;i=i+10)
    {
       moveto(10+i,268);
       lineto(10+i,272);
    }
    moveto(10,210);
    lineto(360,210);
    ch=0;
    for(eps=0.001;eps>=0.000000000000001;eps=eps/10)
    {
    ch++;
    ///////////////////////////////////////////
     
/*    for(m=1;m<=N;m++)
    {
       F[m][m]=1+eps;
    }
    for(m=1;m<=N-1;m++)
    {
       for(k=1;k<=M-m;k++)
       {
          F[k][m+k]=eps;
       }
    }
    for(m=1;m<=N-1;m++)
    {
       for(k=1;k<=M-m;k++)
       {
          F[k+m][k]=-1-eps;
       } 
    }
    for(m=1;m<=N-1;m++)
    {
       S[m]=-1;
    }
    S[N]=1+eps;
*/  
    for(m=1;m<=N;m++)
    {
       for(k=1;k<=M;k++)
       {
          if (m=k) F[k][m]=1+eps;
       } 
    }  
    for(m=1;m<=N;m++)
    {
       for(k=1;k<=M;k++)
       {
          if (m>k) F[k][m]=eps;
       } 
    }  
    for(m=1;m<=N;m++)
    {
       for(k=1;k<=M;k++)
       {
          if (m<k) F[k][m]=-1-eps;
       } 
    } 
    for(k=1;k<=M-1;k++)
    {
       S[k]=-1;
    } 
    S[M]=1+eps ;
          
              
  
//fprintf(outf,"%2.5f   %2.5f\n",S[N],F[N][N]);
/*  for( m=1; m<=N; m++)   
    { 
       fprintf(outf,"\n");
       for(k=1;k<=M;k++)
       {
       fprintf(outf, "%2.5f\n",F[m][k]);
       }       
    }
    
//*/    
    
    for(L=1;L<=O-1;L++)
    {
       for(I=L+1;I<=N;I++)
       {
          F[I][L]=F[I][L]/F[L][L];
       }
       S[L]=S[L]/F[L][L];
       
       for(I=L+1;I<=N;I++)
       {
          for(J=L+1;J<=M;J++)
          {
             F[J][I]=F[J][I]-F[L][I]*F[J][L];
          }
          S[I]=S[I]-S[L]*F[L][I];
          F[L][I]=0;
       }
       F[L][L]=1;
       
    } 
/*
   for( m=1; m<=N; m++)   
    { 
       fprintf(outf,"\n");
       for(k=1;k<=M;k++)
       {
       fprintf(outf, "%2.5f\n",F[m][k]);
       }       
    }
*/          

//     fprintf(outf,"%2.5f   %2.5f\n",S[N],F[N][N]);
    X[N]=S[N]/F[N][N];
    
   

    for(I=N-1;I>=1;I--)
    {
       L=N;
       O=I;
       while((N-O)>0)
       {
          S[I]=S[I]-F[L][I]*X[L];
          X[I]=S[I];
          L=L-1;
          O=O+1;
       }
    } 
    mo=0;
    for(m=1;m<=N;m++)
    {
//       fprintf(outf, "X %d =  %2.40f\n",m,X[m]);
       if (X[m]>=0) 
       mo=mo+X[m];
       else
       mo=mo-X[m];
                     
    }  
    fprintf(outf, "%2.40f\n",mo);
    X1[ch]=mo*200;
    }
    moveto(20,X1[1]);
    for(i=2;i=15;i++)
    {
    lineto((i+1)*22,X1[i]+210);       
    }
 
    getchar();
    getch();
    closegraph();
  return 0;
}      
  
  
  
  
  
/*
#include <graphics.h>
int main()
{
 initwindow(400,300);
 moveto(0,0);
 lineto(50,50);
 getch();
 closegraph();
 return 0;
}
*/    
